package com.example.opengldemo.vertex_magical.shader;


import com.example.opengldemo.util.MatrixState;

import java.util.ArrayList;
import java.util.List;

public class ArrayRenderer extends LazyRenderer {
    private List<BaseRenderer> listRenderer  ;


    public ArrayRenderer() {
        super();
        this.listRenderer = new ArrayList<>();
    }

    public void addRenderer(BaseRenderer baseRenderer){
        synchronized (listRenderer){
            listRenderer.add(baseRenderer) ;
        }
    }

    public void clearRenderer(BaseRenderer baseRenderer){
        synchronized (listRenderer){
            listRenderer.clear();
        }
    }

    @Override
    public void create() {
        super.create();
        synchronized (listRenderer){
            for (BaseRenderer item : listRenderer
                    ) {
                item.create();
            }
        }
    }

    @Override
    public void sizeChanged(int width, int height) {
        super.sizeChanged(width , height);
        synchronized (listRenderer){
            for (BaseRenderer item : listRenderer
            ) {
                item.sizeChanged(width , height);
            }
        }
    }

    @Override
    public void draw(int texture) {
        synchronized (listRenderer){
            super.draw(texture);
            for (BaseRenderer item : listRenderer
            ) { item.draw(texture);
            }
        }

    }

    @Override
    public void destroy() {
        synchronized (listRenderer){
            for (BaseRenderer item : listRenderer
            ) {
                item.destroy();
            }
            super.destroy();
        }

    }
}
